package com.threaddemo4;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class AllOfAnyOfDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("F1 " + Thread.currentThread().getName());

            return "F1 返回值";
        });

        CompletableFuture<String> f2 = CompletableFuture.supplyAsync(()->{
            System.out.println("F2 " + Thread.currentThread().getName());

            return "F2 返回值";
        });

        CompletableFuture<String> f3 = CompletableFuture.supplyAsync(()->{
            System.out.println("F3 " + Thread.currentThread().getName());
            int a = 10 / 0;
            return "F3 返回值";
        });

        CompletableFuture anyOf = CompletableFuture.anyOf(f1,f2,f3).whenComplete((a,b)->{
            System.out.println("anyOf 执行。。。。");
            System.out.println("a = " + a);
            System.out.println("b = " + b.getMessage());
        });

        System.out.println("f1 = " + f1.get());
        System.out.println("f2 = " + f2.get());
        System.out.println("f3 = " + f3.get());
        System.out.println("anyOf = " + anyOf.get());

    }
}
